﻿namespace FrameWork.Lib.HTML
{
    using System;
    using System.IO;
    using System.Text;

    internal abstract class HtmlEncoder
    {
        protected HtmlEncoder()
        {
        }

        public static string DecodeValue(string value)
        {
            StringBuilder builder = new StringBuilder();
            StringReader reader = new StringReader(value);
            int num = reader.Read();
            while (num != -1)
            {
                StringBuilder builder2 = new StringBuilder();
                while ((num != 0x26) && (num != -1))
                {
                    builder2.Append((char) num);
                    num = reader.Read();
                }
                builder.Append(builder2.ToString());
                if (num == 0x26)
                {
                    builder2 = new StringBuilder();
                    while ((num != 0x3b) && (num != -1))
                    {
                        builder2.Append((char) num);
                        num = reader.Read();
                    }
                    if (num == 0x3b)
                    {
                        num = reader.Read();
                        builder2.Append(';');
                        if (builder2[1] == '#')
                        {
                            int num2 = int.Parse(builder2.ToString().Substring(2, builder2.Length - 3));
                            builder.Append((char) num2);
                        }
                        else
                        {
                            switch (builder2.ToString())
                            {
                                case "&lt;":
                                    builder.Append("<");
                                    break;

                                case "&gt;":
                                    builder.Append(">");
                                    break;

                                case "&quot;":
                                    builder.Append("\"");
                                    break;

                                case "&amp;":
                                    builder.Append("&");
                                    break;

                                case "&Aacute;":
                                    builder.Append('\x00c1');
                                    break;

                                case "&aacute;":
                                    builder.Append('\x00e1');
                                    break;

                                case "&Acirc;":
                                    builder.Append('\x00c2');
                                    break;

                                case "&acirc;":
                                    builder.Append('\x00e2');
                                    break;

                                case "&acute;":
                                    builder.Append('\x00b4');
                                    break;

                                case "&AElig;":
                                    builder.Append('\x00c6');
                                    break;

                                case "&aelig;":
                                    builder.Append('\x00e6');
                                    break;

                                case "&Agrave;":
                                    builder.Append('\x00c0');
                                    break;

                                case "&agrave;":
                                    builder.Append('\x00e0');
                                    break;

                                case "&alefsym;":
                                    builder.Append('ℵ');
                                    break;

                                case "&Alpha;":
                                    builder.Append('Α');
                                    break;

                                case "&alpha;":
                                    builder.Append('α');
                                    break;

                                case "&and;":
                                    builder.Append('∧');
                                    break;

                                case "&ang;":
                                    builder.Append('∠');
                                    break;

                                case "&Aring;":
                                    builder.Append('\x00c5');
                                    break;

                                case "&aring;":
                                    builder.Append('\x00e5');
                                    break;

                                case "&asymp;":
                                    builder.Append('≈');
                                    break;

                                case "&Atilde;":
                                    builder.Append('\x00c3');
                                    break;

                                case "&atilde;":
                                    builder.Append('\x00e3');
                                    break;

                                case "&Auml;":
                                    builder.Append('\x00c4');
                                    break;

                                case "&auml;":
                                    builder.Append('\x00e4');
                                    break;

                                case "&bdquo;":
                                    builder.Append('„');
                                    break;

                                case "&Beta;":
                                    builder.Append('Β');
                                    break;

                                case "&beta;":
                                    builder.Append('β');
                                    break;

                                case "&brvbar;":
                                    builder.Append('\x00a6');
                                    break;

                                case "&bull;":
                                    builder.Append('•');
                                    break;

                                case "&cap;":
                                    builder.Append('∩');
                                    break;

                                case "&Ccedil;":
                                    builder.Append('\x00c7');
                                    break;

                                case "&ccedil;":
                                    builder.Append('\x00e7');
                                    break;

                                case "&cedil;":
                                    builder.Append('\x00b8');
                                    break;

                                case "&cent;":
                                    builder.Append('\x00a2');
                                    break;

                                case "&Chi;":
                                    builder.Append('Χ');
                                    break;

                                case "&chi;":
                                    builder.Append('χ');
                                    break;

                                case "&circ;":
                                    builder.Append('ˆ');
                                    break;

                                case "&clubs;":
                                    builder.Append('♣');
                                    break;

                                case "&cong;":
                                    builder.Append('≅');
                                    break;

                                case "&copy;":
                                    builder.Append('\x00a9');
                                    break;

                                case "&crarr;":
                                    builder.Append('↵');
                                    break;

                                case "&cup;":
                                    builder.Append('∪');
                                    break;

                                case "&curren;":
                                    builder.Append('\x00a4');
                                    break;

                                case "&dagger;":
                                    builder.Append('†');
                                    break;

                                case "&Dagger;":
                                    builder.Append('‡');
                                    break;

                                case "&darr;":
                                    builder.Append('↓');
                                    break;

                                case "&dArr;":
                                    builder.Append('⇓');
                                    break;

                                case "&deg;":
                                    builder.Append('\x00b0');
                                    break;

                                case "&Delta;":
                                    builder.Append('Δ');
                                    break;

                                case "&delta;":
                                    builder.Append('δ');
                                    break;

                                case "&diams;":
                                    builder.Append('♦');
                                    break;

                                case "&divide;":
                                    builder.Append('\x00f7');
                                    break;

                                case "&Eacute;":
                                    builder.Append('\x00c9');
                                    break;

                                case "&eacute;":
                                    builder.Append('\x00e9');
                                    break;

                                case "&Ecirc;":
                                    builder.Append('\x00ca');
                                    break;

                                case "&ecirc;":
                                    builder.Append('\x00ea');
                                    break;

                                case "&Egrave;":
                                    builder.Append('\x00c8');
                                    break;

                                case "&egrave;":
                                    builder.Append('\x00e8');
                                    break;

                                case "&empty;":
                                    builder.Append('∅');
                                    break;

                                case "&emsp;":
                                    builder.Append(' ');
                                    break;

                                case "&Epsilon;":
                                    builder.Append('Ε');
                                    break;

                                case "&epsilon;":
                                    builder.Append('ε');
                                    break;

                                case "&equiv;":
                                    builder.Append('≡');
                                    break;

                                case "&Eta;":
                                    builder.Append('Η');
                                    break;

                                case "&eta;":
                                    builder.Append('η');
                                    break;

                                case "&ETH;":
                                    builder.Append('\x00d0');
                                    break;

                                case "&eth;":
                                    builder.Append('\x00f0');
                                    break;

                                case "&Euml;":
                                    builder.Append('\x00cb');
                                    break;

                                case "&euml;":
                                    builder.Append('\x00eb');
                                    break;

                                case "&euro;":
                                    builder.Append('\x0080');
                                    break;

                                case "&exist;":
                                    builder.Append('∃');
                                    break;

                                case "&fnof;":
                                    builder.Append('ƒ');
                                    break;

                                case "&forall;":
                                    builder.Append('∀');
                                    break;

                                case "&frac12;":
                                    builder.Append('\x00bd');
                                    break;

                                case "&frac14;":
                                    builder.Append('\x00bc');
                                    break;

                                case "&frac34;":
                                    builder.Append('\x00be');
                                    break;

                                case "&fras1;":
                                    builder.Append('⁄');
                                    break;

                                case "&Gamma;":
                                    builder.Append('Γ');
                                    break;

                                case "&gamma;":
                                    builder.Append('γ');
                                    break;

                                case "&ge;":
                                    builder.Append('≥');
                                    break;

                                case "&harr;":
                                    builder.Append('↔');
                                    break;

                                case "&hArr;":
                                    builder.Append('⇔');
                                    break;

                                case "&hearts;":
                                    builder.Append('♥');
                                    break;

                                case "&hellip;":
                                    builder.Append('…');
                                    break;

                                case "&Iacute;":
                                    builder.Append('\x00cd');
                                    break;

                                case "&iacute;":
                                    builder.Append('\x00ed');
                                    break;

                                case "&Icirc;":
                                    builder.Append('\x00ce');
                                    break;

                                case "&icirc;":
                                    builder.Append('\x00ee');
                                    break;

                                case "&iexcl;":
                                    builder.Append('\x00a1');
                                    break;

                                case "&Igrave;":
                                    builder.Append('\x00cc');
                                    break;

                                case "&igrave;":
                                    builder.Append('\x00ec');
                                    break;

                                case "&image;":
                                    builder.Append('ℑ');
                                    break;

                                case "&infin;":
                                    builder.Append('∞');
                                    break;

                                case "&int;":
                                    builder.Append('∫');
                                    break;

                                case "&Iota;":
                                    builder.Append('Ι');
                                    break;

                                case "&iota;":
                                    builder.Append('ι');
                                    break;

                                case "&iquest;":
                                    builder.Append('\x00bf');
                                    break;

                                case "&isin;":
                                    builder.Append('∈');
                                    break;

                                case "&Iuml;":
                                    builder.Append('\x00cf');
                                    break;

                                case "&iuml;":
                                    builder.Append('\x00ef');
                                    break;

                                case "&Kappa;":
                                    builder.Append('Κ');
                                    break;

                                case "&kappa;":
                                    builder.Append('κ');
                                    break;

                                case "&Lambda;":
                                    builder.Append('Λ');
                                    break;

                                case "&lambda;":
                                    builder.Append('λ');
                                    break;

                                case "&lang;":
                                    builder.Append('〈');
                                    break;

                                case "&laquo;":
                                    builder.Append('\x00ab');
                                    break;

                                case "&larr;":
                                    builder.Append('←');
                                    break;

                                case "&lArr;":
                                    builder.Append('⇐');
                                    break;

                                case "&lceil;":
                                    builder.Append('⌈');
                                    break;

                                case "&ldquo;":
                                    builder.Append('“');
                                    break;

                                case "&le;":
                                    builder.Append('≤');
                                    break;

                                case "&lfloor;":
                                    builder.Append('⌊');
                                    break;

                                case "&lowast;":
                                    builder.Append('∗');
                                    break;

                                case "&loz;":
                                    builder.Append('◊');
                                    break;

                                case "&lrm;":
                                    builder.Append('‎');
                                    break;

                                case "&lsaquo;":
                                    builder.Append('‹');
                                    break;

                                case "&lsquo;":
                                    builder.Append('‘');
                                    break;

                                case "&macr;":
                                    builder.Append('\x00af');
                                    break;

                                case "&mdash;":
                                    builder.Append('—');
                                    break;

                                case "&micro;":
                                    builder.Append('\x00b5');
                                    break;

                                case "&middot;":
                                    builder.Append('\x00b7');
                                    break;

                                case "&minus;":
                                    builder.Append('−');
                                    break;

                                case "&Mu;":
                                    builder.Append('Μ');
                                    break;

                                case "&mu;":
                                    builder.Append('μ');
                                    break;

                                case "&nabla;":
                                    builder.Append('∇');
                                    break;

                                case "&nbsp;":
                                    builder.Append('\x00a0');
                                    break;

                                case "&ndash;":
                                    builder.Append('–');
                                    break;

                                case "&ne;":
                                    builder.Append('≠');
                                    break;

                                case "&ni;":
                                    builder.Append('∋');
                                    break;

                                case "&not;":
                                    builder.Append('\x00ac');
                                    break;

                                case "&notin;":
                                    builder.Append('∉');
                                    break;

                                case "&nsub;":
                                    builder.Append('⊄');
                                    break;

                                case "&Ntilde;":
                                    builder.Append('\x00d1');
                                    break;

                                case "&ntilde;":
                                    builder.Append('\x00f1');
                                    break;

                                case "&Nu;":
                                    builder.Append('Ν');
                                    break;

                                case "&nu;":
                                    builder.Append('ν');
                                    break;

                                case "&Oacute;":
                                    builder.Append('\x00d3');
                                    break;

                                case "&oacute;":
                                    builder.Append('\x00f3');
                                    break;

                                case "&Ocirc;":
                                    builder.Append('\x00d4');
                                    break;

                                case "&ocirc;":
                                    builder.Append('\x00f4');
                                    break;

                                case "&OElig;":
                                    builder.Append('Œ');
                                    break;

                                case "&oelig;":
                                    builder.Append('œ');
                                    break;

                                case "&Ograve;":
                                    builder.Append('\x00d2');
                                    break;

                                case "&ograve;":
                                    builder.Append('\x00f2');
                                    break;

                                case "&oline;":
                                    builder.Append('‾');
                                    break;

                                case "&Omega;":
                                    builder.Append('Ω');
                                    break;

                                case "&omega;":
                                    builder.Append('ω');
                                    break;

                                case "&Omicron;":
                                    builder.Append('Ο');
                                    break;

                                case "&omicron;":
                                    builder.Append('ο');
                                    break;

                                case "&oplus;":
                                    builder.Append('⊕');
                                    break;

                                case "&or;":
                                    builder.Append('∨');
                                    break;

                                case "&ordf;":
                                    builder.Append('\x00aa');
                                    break;

                                case "&ordm;":
                                    builder.Append('\x00ba');
                                    break;

                                case "&Oslash;":
                                    builder.Append('\x00d8');
                                    break;

                                case "&oslash;":
                                    builder.Append('\x00f8');
                                    break;

                                case "&Otilde;":
                                    builder.Append('\x00d5');
                                    break;

                                case "&otilde;":
                                    builder.Append('\x00f5');
                                    break;

                                case "&otimes;":
                                    builder.Append('⊗');
                                    break;

                                case "&Ouml;":
                                    builder.Append('\x00d6');
                                    break;

                                case "&ouml;":
                                    builder.Append('\x00f6');
                                    break;

                                case "&para;":
                                    builder.Append('\x00b6');
                                    break;

                                case "&part;":
                                    builder.Append('∂');
                                    break;

                                case "&permil;":
                                    builder.Append('‰');
                                    break;

                                case "&perp;":
                                    builder.Append('⊥');
                                    break;

                                case "&Phi;":
                                    builder.Append('Φ');
                                    break;

                                case "&phi;":
                                    builder.Append('φ');
                                    break;

                                case "&Pi;":
                                    builder.Append('Π');
                                    break;

                                case "&pi;":
                                    builder.Append('π');
                                    break;

                                case "&piv;":
                                    builder.Append('ϖ');
                                    break;

                                case "&plusmn;":
                                    builder.Append('\x00b1');
                                    break;

                                case "&pound;":
                                    builder.Append('\x00a3');
                                    break;

                                case "&prime;":
                                    builder.Append('′');
                                    break;

                                case "&Prime;":
                                    builder.Append('″');
                                    break;

                                case "&prod;":
                                    builder.Append('∏');
                                    break;

                                case "&prop;":
                                    builder.Append('∝');
                                    break;

                                case "&Psi;":
                                    builder.Append('Ψ');
                                    break;

                                case "&psi;":
                                    builder.Append('ψ');
                                    break;

                                case "&radic;":
                                    builder.Append('√');
                                    break;

                                case "&rang;":
                                    builder.Append('〉');
                                    break;

                                case "&raquo;":
                                    builder.Append('\x00bb');
                                    break;

                                case "&rarr;":
                                    builder.Append('→');
                                    break;

                                case "&rArr;":
                                    builder.Append('⇒');
                                    break;

                                case "&rceil;":
                                    builder.Append('⌉');
                                    break;

                                case "&rdquo;":
                                    builder.Append('”');
                                    break;

                                case "&real;":
                                    builder.Append('ℜ');
                                    break;

                                case "&reg;":
                                    builder.Append('\x00ae');
                                    break;

                                case "&rfloor;":
                                    builder.Append('⌋');
                                    break;

                                case "&Rho;":
                                    builder.Append('Ρ');
                                    break;

                                case "&rho;":
                                    builder.Append('ρ');
                                    break;

                                case "&rlm;":
                                    builder.Append('‏');
                                    break;

                                case "&rsaquo;":
                                    builder.Append('›');
                                    break;

                                case "&rsquo;":
                                    builder.Append('’');
                                    break;

                                case "&sbquo;":
                                    builder.Append('‚');
                                    break;

                                case "&Scaron;":
                                    builder.Append('Š');
                                    break;

                                case "&scaron;":
                                    builder.Append('š');
                                    break;

                                case "&sdot;":
                                    builder.Append('⋅');
                                    break;

                                case "&sect;":
                                    builder.Append('\x00a7');
                                    break;

                                case "&shy;":
                                    builder.Append('\x00ad');
                                    break;

                                case "&Sigma;":
                                    builder.Append('Σ');
                                    break;

                                case "&sigma;":
                                    builder.Append('σ');
                                    break;

                                case "&sigmaf;":
                                    builder.Append('ς');
                                    break;

                                case "&sim;":
                                    builder.Append('∼');
                                    break;

                                case "&spades;":
                                    builder.Append('♠');
                                    break;

                                case "&sub;":
                                    builder.Append('⊂');
                                    break;

                                case "&sube;":
                                    builder.Append('⊆');
                                    break;

                                case "&sum;":
                                    builder.Append('∑');
                                    break;

                                case "&sup;":
                                    builder.Append('⊃');
                                    break;

                                case "&sup1;":
                                    builder.Append('\x00b9');
                                    break;

                                case "&sup2;":
                                    builder.Append('\x00b2');
                                    break;

                                case "&sup3;":
                                    builder.Append('\x00b3');
                                    break;

                                case "&supe;":
                                    builder.Append('⊇');
                                    break;

                                case "&szlig;":
                                    builder.Append('\x00df');
                                    break;

                                case "&Tau;":
                                    builder.Append('Τ');
                                    break;

                                case "&tau;":
                                    builder.Append('τ');
                                    break;

                                case "&there4;":
                                    builder.Append('∴');
                                    break;

                                case "&Theta;":
                                    builder.Append('Θ');
                                    break;

                                case "&theta;":
                                    builder.Append('θ');
                                    break;

                                case "&thetasym;":
                                    builder.Append('ϑ');
                                    break;

                                case "&thinsp;":
                                    builder.Append(' ');
                                    break;

                                case "&THORN;":
                                    builder.Append('\x00de');
                                    break;

                                case "&thorn;":
                                    builder.Append('\x00fe');
                                    break;

                                case "&tilde;":
                                    builder.Append('˜');
                                    break;

                                case "&times;":
                                    builder.Append('\x00d7');
                                    break;

                                case "&trade;":
                                    builder.Append('™');
                                    break;

                                case "&Uacute;":
                                    builder.Append('\x00da');
                                    break;

                                case "&uacute;":
                                    builder.Append('\x00fa');
                                    break;

                                case "&uarr;":
                                    builder.Append('↑');
                                    break;

                                case "&uArr;":
                                    builder.Append('⇑');
                                    break;

                                case "&Ucirc;":
                                    builder.Append('\x00db');
                                    break;

                                case "&ucirc;":
                                    builder.Append('\x00fb');
                                    break;

                                case "&Ugrave;":
                                    builder.Append('\x00d9');
                                    break;

                                case "&ugrave;":
                                    builder.Append('\x00f9');
                                    break;

                                case "&uml;":
                                    builder.Append('\x00a8');
                                    break;

                                case "&upsih;":
                                    builder.Append('ϒ');
                                    break;

                                case "&Upsilon;":
                                    builder.Append('Υ');
                                    break;

                                case "&upsilon;":
                                    builder.Append('υ');
                                    break;

                                case "&Uuml;":
                                    builder.Append('\x00dc');
                                    break;

                                case "&uuml;":
                                    builder.Append('\x00fc');
                                    break;

                                case "&weierp;":
                                    builder.Append('℘');
                                    break;

                                case "&Xi;":
                                    builder.Append('Ξ');
                                    break;

                                case "&xi;":
                                    builder.Append('ξ');
                                    break;

                                case "&Yacute;":
                                    builder.Append('\x00dd');
                                    break;

                                case "&yacute;":
                                    builder.Append('\x00fd');
                                    break;

                                case "&yen;":
                                    builder.Append('\x00a5');
                                    break;

                                case "&Yuml;":
                                    builder.Append('Ÿ');
                                    break;

                                case "&yuml;":
                                    builder.Append('\x00ff');
                                    break;

                                case "&Zeta;":
                                    builder.Append('Ζ');
                                    break;

                                case "&zeta;":
                                    builder.Append('ζ');
                                    break;

                                case "&zwj;":
                                    builder.Append('‍');
                                    break;

                                case "&zwnj;":
                                    builder.Append('‌');
                                    break;

                                default:
                                    builder.Append(builder2.ToString());
                                    break;
                            }
                        }
                    }
                    else
                    {
                        builder.Append(builder2.ToString());
                    }
                }
            }
            return builder.ToString();
        }

        public static string EncodeValue(string value)
        {
            StringBuilder builder = new StringBuilder();
            StringReader reader = new StringReader(value);
            for (int i = reader.Read(); i != -1; i = reader.Read())
            {
                switch (i)
                {
                    case 0x22:
                    {
                        builder.Append("&quot;");
                        continue;
                    }
                    case 0x26:
                    {
                        builder.Append("&amp;");
                        continue;
                    }
                    case 60:
                    {
                        builder.Append("&lt;");
                        continue;
                    }
                    case 0x3e:
                    {
                        builder.Append("&gt;");
                        continue;
                    }
                    case 0x80:
                    {
                        builder.Append("&euro;");
                        continue;
                    }
                    case 160:
                    {
                        builder.Append("&nbsp;");
                        continue;
                    }
                    case 0xa1:
                    {
                        builder.Append("&iexcl;");
                        continue;
                    }
                    case 0xa2:
                    {
                        builder.Append("&cent;");
                        continue;
                    }
                    case 0xa3:
                    {
                        builder.Append("&pound;");
                        continue;
                    }
                    case 0xa4:
                    {
                        builder.Append("&curren;");
                        continue;
                    }
                    case 0xa5:
                    {
                        builder.Append("&yen;");
                        continue;
                    }
                    case 0xa6:
                    {
                        builder.Append("&brvbar;");
                        continue;
                    }
                    case 0xa7:
                    {
                        builder.Append("&sect;");
                        continue;
                    }
                    case 0xa8:
                    {
                        builder.Append("&uml;");
                        continue;
                    }
                    case 0xa9:
                    {
                        builder.Append("&copy;");
                        continue;
                    }
                    case 170:
                    {
                        builder.Append("&ordf;");
                        continue;
                    }
                    case 0xab:
                    {
                        builder.Append("&laquo;");
                        continue;
                    }
                    case 0xac:
                    {
                        builder.Append("&not;");
                        continue;
                    }
                    case 0xad:
                    {
                        builder.Append("&shy;");
                        continue;
                    }
                    case 0xae:
                    {
                        builder.Append("&reg;");
                        continue;
                    }
                    case 0xaf:
                    {
                        builder.Append("&macr;");
                        continue;
                    }
                    case 0xb0:
                    {
                        builder.Append("&deg;");
                        continue;
                    }
                    case 0xb1:
                    {
                        builder.Append("&plusmn;");
                        continue;
                    }
                    case 0xb2:
                    {
                        builder.Append("&sup2;");
                        continue;
                    }
                    case 0xb3:
                    {
                        builder.Append("&sup3;");
                        continue;
                    }
                    case 180:
                    {
                        builder.Append("&acute;");
                        continue;
                    }
                    case 0xb5:
                    {
                        builder.Append("&micro;");
                        continue;
                    }
                    case 0xb6:
                    {
                        builder.Append("&para;");
                        continue;
                    }
                    case 0xb7:
                    {
                        builder.Append("&middot;");
                        continue;
                    }
                    case 0xb8:
                    {
                        builder.Append("&cedil;");
                        continue;
                    }
                    case 0xb9:
                    {
                        builder.Append("&sup1;");
                        continue;
                    }
                    case 0xba:
                    {
                        builder.Append("&ordm;");
                        continue;
                    }
                    case 0xbb:
                    {
                        builder.Append("&raquo;");
                        continue;
                    }
                    case 0xbc:
                    {
                        builder.Append("&frac14;");
                        continue;
                    }
                    case 0xbd:
                    {
                        builder.Append("&frac12;");
                        continue;
                    }
                    case 190:
                    {
                        builder.Append("&frac34;");
                        continue;
                    }
                    case 0xbf:
                    {
                        builder.Append("&iquest;");
                        continue;
                    }
                    case 0xc0:
                    {
                        builder.Append("&Agrave;");
                        continue;
                    }
                    case 0xc1:
                    {
                        builder.Append("&Aacute;");
                        continue;
                    }
                    case 0xc2:
                    {
                        builder.Append("&Acirc;");
                        continue;
                    }
                    case 0xc3:
                    {
                        builder.Append("&Atilde;");
                        continue;
                    }
                    case 0xc4:
                    {
                        builder.Append("&Auml;");
                        continue;
                    }
                    case 0xc5:
                    {
                        builder.Append("&Aring;");
                        continue;
                    }
                    case 0xc6:
                    {
                        builder.Append("&AElig;");
                        continue;
                    }
                    case 0xc7:
                    {
                        builder.Append("&Ccedil;");
                        continue;
                    }
                    case 200:
                    {
                        builder.Append("&Egrave;");
                        continue;
                    }
                    case 0xc9:
                    {
                        builder.Append("&Eacute;");
                        continue;
                    }
                    case 0xca:
                    {
                        builder.Append("&Ecirc;");
                        continue;
                    }
                    case 0xcb:
                    {
                        builder.Append("&Euml;");
                        continue;
                    }
                    case 0xcc:
                    {
                        builder.Append("&Igrave;");
                        continue;
                    }
                    case 0xcd:
                    {
                        builder.Append("&Iacute;");
                        continue;
                    }
                    case 0xce:
                    {
                        builder.Append("&Icirc;");
                        continue;
                    }
                    case 0xcf:
                    {
                        builder.Append("&Iuml;");
                        continue;
                    }
                    case 0xd0:
                    {
                        builder.Append("&ETH;");
                        continue;
                    }
                    case 0xd1:
                    {
                        builder.Append("&Ntilde;");
                        continue;
                    }
                    case 210:
                    {
                        builder.Append("&Ograve;");
                        continue;
                    }
                    case 0xd3:
                    {
                        builder.Append("&Oacute;");
                        continue;
                    }
                    case 0xd4:
                    {
                        builder.Append("&Ocirc;");
                        continue;
                    }
                    case 0xd5:
                    {
                        builder.Append("&Otilde;");
                        continue;
                    }
                    case 0xd6:
                    {
                        builder.Append("&Ouml;");
                        continue;
                    }
                    case 0xd7:
                    {
                        builder.Append("&times;");
                        continue;
                    }
                    case 0xd8:
                    {
                        builder.Append("&Oslash;");
                        continue;
                    }
                    case 0xd9:
                    {
                        builder.Append("&Ugrave;");
                        continue;
                    }
                    case 0xda:
                    {
                        builder.Append("&Uacute;");
                        continue;
                    }
                    case 0xdb:
                    {
                        builder.Append("&Ucirc;");
                        continue;
                    }
                    case 220:
                    {
                        builder.Append("&Uuml;");
                        continue;
                    }
                    case 0xdd:
                    {
                        builder.Append("&Yacute;");
                        continue;
                    }
                    case 0xde:
                    {
                        builder.Append("&THORN;");
                        continue;
                    }
                    case 0xdf:
                    {
                        builder.Append("&szlig;");
                        continue;
                    }
                    case 0xe0:
                    {
                        builder.Append("&agrave;");
                        continue;
                    }
                    case 0xe1:
                    {
                        builder.Append("&aacute;");
                        continue;
                    }
                    case 0xe2:
                    {
                        builder.Append("&acirc;");
                        continue;
                    }
                    case 0xe3:
                    {
                        builder.Append("&atilde;");
                        continue;
                    }
                    case 0xe4:
                    {
                        builder.Append("&auml;");
                        continue;
                    }
                    case 0xe5:
                    {
                        builder.Append("&aring;");
                        continue;
                    }
                    case 230:
                    {
                        builder.Append("&aelig;");
                        continue;
                    }
                    case 0xe7:
                    {
                        builder.Append("&ccedil;");
                        continue;
                    }
                    case 0xe8:
                    {
                        builder.Append("&egrave;");
                        continue;
                    }
                    case 0xe9:
                    {
                        builder.Append("&eacute;");
                        continue;
                    }
                    case 0xea:
                    {
                        builder.Append("&ecirc;");
                        continue;
                    }
                    case 0xeb:
                    {
                        builder.Append("&euml;");
                        continue;
                    }
                    case 0xec:
                    {
                        builder.Append("&igrave;");
                        continue;
                    }
                    case 0xed:
                    {
                        builder.Append("&iacute;");
                        continue;
                    }
                    case 0xee:
                    {
                        builder.Append("&icirc;");
                        continue;
                    }
                    case 0xef:
                    {
                        builder.Append("&iuml;");
                        continue;
                    }
                    case 240:
                    {
                        builder.Append("&eth;");
                        continue;
                    }
                    case 0xf1:
                    {
                        builder.Append("&ntilde;");
                        continue;
                    }
                    case 0xf2:
                    {
                        builder.Append("&ograve;");
                        continue;
                    }
                    case 0xf3:
                    {
                        builder.Append("&oacute;");
                        continue;
                    }
                    case 0xf4:
                    {
                        builder.Append("&ocirc;");
                        continue;
                    }
                    case 0xf5:
                    {
                        builder.Append("&otilde;");
                        continue;
                    }
                    case 0xf6:
                    {
                        builder.Append("&ouml;");
                        continue;
                    }
                    case 0xf7:
                    {
                        builder.Append("&divide;");
                        continue;
                    }
                    case 0xf8:
                    {
                        builder.Append("&oslash;");
                        continue;
                    }
                    case 0xf9:
                    {
                        builder.Append("&ugrave;");
                        continue;
                    }
                    case 250:
                    {
                        builder.Append("&uacute;");
                        continue;
                    }
                    case 0xfb:
                    {
                        builder.Append("&ucirc;");
                        continue;
                    }
                    case 0xfc:
                    {
                        builder.Append("&uuml;");
                        continue;
                    }
                    case 0xfd:
                    {
                        builder.Append("&yacute;");
                        continue;
                    }
                    case 0xfe:
                    {
                        builder.Append("&thorn;");
                        continue;
                    }
                    case 0xff:
                    {
                        builder.Append("&yuml;");
                        continue;
                    }
                    case 0x152:
                    {
                        builder.Append("&OElig;");
                        continue;
                    }
                    case 0x153:
                    {
                        builder.Append("&oelig;");
                        continue;
                    }
                    case 0x160:
                    {
                        builder.Append("&Scaron;");
                        continue;
                    }
                    case 0x161:
                    {
                        builder.Append("&scaron;");
                        continue;
                    }
                    case 0x178:
                    {
                        builder.Append("&Yuml;");
                        continue;
                    }
                    case 0x192:
                    {
                        builder.Append("&fnof;");
                        continue;
                    }
                    case 0x391:
                    {
                        builder.Append("&Alpha;");
                        continue;
                    }
                    case 0x392:
                    {
                        builder.Append("&Beta;");
                        continue;
                    }
                    case 0x393:
                    {
                        builder.Append("&Gamma;");
                        continue;
                    }
                    case 0x394:
                    {
                        builder.Append("&Delta;");
                        continue;
                    }
                    case 0x395:
                    {
                        builder.Append("&Epsilon;");
                        continue;
                    }
                    case 0x396:
                    {
                        builder.Append("&Zeta;");
                        continue;
                    }
                    case 0x397:
                    {
                        builder.Append("&Eta;");
                        continue;
                    }
                    case 920:
                    {
                        builder.Append("&Theta;");
                        continue;
                    }
                    case 0x399:
                    {
                        builder.Append("&Iota;");
                        continue;
                    }
                    case 0x39a:
                    {
                        builder.Append("&Kappa;");
                        continue;
                    }
                    case 0x39b:
                    {
                        builder.Append("&Lambda;");
                        continue;
                    }
                    case 0x39c:
                    {
                        builder.Append("&Mu;");
                        continue;
                    }
                    case 0x39d:
                    {
                        builder.Append("&Nu;");
                        continue;
                    }
                    case 0x39e:
                    {
                        builder.Append("&Xi;");
                        continue;
                    }
                    case 0x39f:
                    {
                        builder.Append("&Omicron;");
                        continue;
                    }
                    case 0x3a0:
                    {
                        builder.Append("&Pi;");
                        continue;
                    }
                    case 0x3a1:
                    {
                        builder.Append("&Rho;");
                        continue;
                    }
                    case 0x3a3:
                    {
                        builder.Append("&Sigma;");
                        continue;
                    }
                    case 0x3a4:
                    {
                        builder.Append("&Tau;");
                        continue;
                    }
                    case 0x3a5:
                    {
                        builder.Append("&Upsilon;");
                        continue;
                    }
                    case 0x3a6:
                    {
                        builder.Append("&Phi;");
                        continue;
                    }
                    case 0x3a7:
                    {
                        builder.Append("&Chi;");
                        continue;
                    }
                    case 0x3a8:
                    {
                        builder.Append("&Psi;");
                        continue;
                    }
                    case 0x3a9:
                    {
                        builder.Append("&Omega;");
                        continue;
                    }
                    case 0x3b1:
                    {
                        builder.Append("&alpha;");
                        continue;
                    }
                    case 0x3b2:
                    {
                        builder.Append("&beta;");
                        continue;
                    }
                    case 0x3b3:
                    {
                        builder.Append("&gamma;");
                        continue;
                    }
                    case 0x3b4:
                    {
                        builder.Append("&delta;");
                        continue;
                    }
                    case 0x3b5:
                    {
                        builder.Append("&epsilon;");
                        continue;
                    }
                    case 950:
                    {
                        builder.Append("&zeta;");
                        continue;
                    }
                    case 0x3b7:
                    {
                        builder.Append("&eta;");
                        continue;
                    }
                    case 0x3b8:
                    {
                        builder.Append("&theta;");
                        continue;
                    }
                    case 0x3b9:
                    {
                        builder.Append("&iota;");
                        continue;
                    }
                    case 0x3ba:
                    {
                        builder.Append("&kappa;");
                        continue;
                    }
                    case 0x3bb:
                    {
                        builder.Append("&lambda;");
                        continue;
                    }
                    case 0x3bc:
                    {
                        builder.Append("&mu;");
                        continue;
                    }
                    case 0x3bd:
                    {
                        builder.Append("&nu;");
                        continue;
                    }
                    case 0x3be:
                    {
                        builder.Append("&xi;");
                        continue;
                    }
                    case 0x3bf:
                    {
                        builder.Append("&omicron;");
                        continue;
                    }
                    case 960:
                    {
                        builder.Append("&pi;");
                        continue;
                    }
                    case 0x3c1:
                    {
                        builder.Append("&rho;");
                        continue;
                    }
                    case 0x3c2:
                    {
                        builder.Append("&sigmaf;");
                        continue;
                    }
                    case 0x3c3:
                    {
                        builder.Append("&sigma;");
                        continue;
                    }
                    case 0x3c4:
                    {
                        builder.Append("&tau;");
                        continue;
                    }
                    case 0x3c5:
                    {
                        builder.Append("&upsilon;");
                        continue;
                    }
                    case 0x3c6:
                    {
                        builder.Append("&phi;");
                        continue;
                    }
                    case 0x3c7:
                    {
                        builder.Append("&chi;");
                        continue;
                    }
                    case 0x3c8:
                    {
                        builder.Append("&psi;");
                        continue;
                    }
                    case 0x3c9:
                    {
                        builder.Append("&omega;");
                        continue;
                    }
                    case 0x3d1:
                    {
                        builder.Append("&thetasym;");
                        continue;
                    }
                    case 0x3d2:
                    {
                        builder.Append("&upsih;");
                        continue;
                    }
                    case 0x3d6:
                    {
                        builder.Append("&piv;");
                        continue;
                    }
                    case 0x2dc:
                    {
                        builder.Append("&tilde;");
                        continue;
                    }
                    case 710:
                    {
                        builder.Append("&circ;");
                        continue;
                    }
                    case 0x2003:
                    {
                        builder.Append("&emsp;");
                        continue;
                    }
                    case 0x2009:
                    {
                        builder.Append("&thinsp;");
                        continue;
                    }
                    case 0x200c:
                    {
                        builder.Append("&zwnj;");
                        continue;
                    }
                    case 0x200d:
                    {
                        builder.Append("&zwj;");
                        continue;
                    }
                    case 0x200e:
                    {
                        builder.Append("&lrm;");
                        continue;
                    }
                    case 0x200f:
                    {
                        builder.Append("&rlm;");
                        continue;
                    }
                    case 0x2013:
                    {
                        builder.Append("&ndash;");
                        continue;
                    }
                    case 0x2014:
                    {
                        builder.Append("&mdash;");
                        continue;
                    }
                    case 0x2018:
                    {
                        builder.Append("&lsquo;");
                        continue;
                    }
                    case 0x2019:
                    {
                        builder.Append("&rsquo;");
                        continue;
                    }
                    case 0x201a:
                    {
                        builder.Append("&sbquo;");
                        continue;
                    }
                    case 0x201c:
                    {
                        builder.Append("&ldquo;");
                        continue;
                    }
                    case 0x201d:
                    {
                        builder.Append("&rdquo;");
                        continue;
                    }
                    case 0x201e:
                    {
                        builder.Append("&bdquo;");
                        continue;
                    }
                    case 0x2020:
                    {
                        builder.Append("&dagger;");
                        continue;
                    }
                    case 0x2021:
                    {
                        builder.Append("&Dagger;");
                        continue;
                    }
                    case 0x2022:
                    {
                        builder.Append("&bull;");
                        continue;
                    }
                    case 0x2026:
                    {
                        builder.Append("&hellip;");
                        continue;
                    }
                    case 0x2030:
                    {
                        builder.Append("&permil;");
                        continue;
                    }
                    case 0x2032:
                    {
                        builder.Append("&prime;");
                        continue;
                    }
                    case 0x2033:
                    {
                        builder.Append("&Prime;");
                        continue;
                    }
                    case 0x2039:
                    {
                        builder.Append("&lsaquo;");
                        continue;
                    }
                    case 0x203a:
                    {
                        builder.Append("&rsaquo;");
                        continue;
                    }
                    case 0x203e:
                    {
                        builder.Append("&oline;");
                        continue;
                    }
                    case 0x2044:
                    {
                        builder.Append("&fras1;");
                        continue;
                    }
                    case 0x2111:
                    {
                        builder.Append("&image;");
                        continue;
                    }
                    case 0x2118:
                    {
                        builder.Append("&weierp;");
                        continue;
                    }
                    case 0x211c:
                    {
                        builder.Append("&real;");
                        continue;
                    }
                    case 0x2122:
                    {
                        builder.Append("&trade;");
                        continue;
                    }
                    case 0x2190:
                    {
                        builder.Append("&larr;");
                        continue;
                    }
                    case 0x2191:
                    {
                        builder.Append("&uarr;");
                        continue;
                    }
                    case 0x2192:
                    {
                        builder.Append("&rarr;");
                        continue;
                    }
                    case 0x2193:
                    {
                        builder.Append("&darr;");
                        continue;
                    }
                    case 0x2194:
                    {
                        builder.Append("&harr;");
                        continue;
                    }
                    case 0x2135:
                    {
                        builder.Append("&alefsym;");
                        continue;
                    }
                    case 0x21d0:
                    {
                        builder.Append("&lArr;");
                        continue;
                    }
                    case 0x21d1:
                    {
                        builder.Append("&uArr;");
                        continue;
                    }
                    case 0x21d2:
                    {
                        builder.Append("&rArr;");
                        continue;
                    }
                    case 0x21d3:
                    {
                        builder.Append("&dArr;");
                        continue;
                    }
                    case 0x21d4:
                    {
                        builder.Append("&hArr;");
                        continue;
                    }
                    case 0x21b5:
                    {
                        builder.Append("&crarr;");
                        continue;
                    }
                    case 0x2200:
                    {
                        builder.Append("&forall;");
                        continue;
                    }
                    case 0x2202:
                    {
                        builder.Append("&part;");
                        continue;
                    }
                    case 0x2203:
                    {
                        builder.Append("&exist;");
                        continue;
                    }
                    case 0x2205:
                    {
                        builder.Append("&empty;");
                        continue;
                    }
                    case 0x2207:
                    {
                        builder.Append("&nabla;");
                        continue;
                    }
                    case 0x2208:
                    {
                        builder.Append("&isin;");
                        continue;
                    }
                    case 0x2209:
                    {
                        builder.Append("&notin;");
                        continue;
                    }
                    case 0x220b:
                    {
                        builder.Append("&ni;");
                        continue;
                    }
                    case 0x220f:
                    {
                        builder.Append("&prod;");
                        continue;
                    }
                    case 0x2211:
                    {
                        builder.Append("&sum;");
                        continue;
                    }
                    case 0x2212:
                    {
                        builder.Append("&minus;");
                        continue;
                    }
                    case 0x221a:
                    {
                        builder.Append("&radic;");
                        continue;
                    }
                    case 0x221d:
                    {
                        builder.Append("&prop;");
                        continue;
                    }
                    case 0x221e:
                    {
                        builder.Append("&infin;");
                        continue;
                    }
                    case 0x2220:
                    {
                        builder.Append("&ang;");
                        continue;
                    }
                    case 0x2217:
                    {
                        builder.Append("&lowast;");
                        continue;
                    }
                    case 0x2227:
                    {
                        builder.Append("&and;");
                        continue;
                    }
                    case 0x2228:
                    {
                        builder.Append("&or;");
                        continue;
                    }
                    case 0x2229:
                    {
                        builder.Append("&cap;");
                        continue;
                    }
                    case 0x222a:
                    {
                        builder.Append("&cup;");
                        continue;
                    }
                    case 0x222b:
                    {
                        builder.Append("&int;");
                        continue;
                    }
                    case 0x2234:
                    {
                        builder.Append("&there4;");
                        continue;
                    }
                    case 0x223c:
                    {
                        builder.Append("&sim;");
                        continue;
                    }
                    case 0x2245:
                    {
                        builder.Append("&cong;");
                        continue;
                    }
                    case 0x2248:
                    {
                        builder.Append("&asymp;");
                        continue;
                    }
                    case 0x2260:
                    {
                        builder.Append("&ne;");
                        continue;
                    }
                    case 0x2261:
                    {
                        builder.Append("&equiv;");
                        continue;
                    }
                    case 0x2264:
                    {
                        builder.Append("&le;");
                        continue;
                    }
                    case 0x2265:
                    {
                        builder.Append("&ge;");
                        continue;
                    }
                    case 0x2282:
                    {
                        builder.Append("&sub;");
                        continue;
                    }
                    case 0x2283:
                    {
                        builder.Append("&sup;");
                        continue;
                    }
                    case 0x2284:
                    {
                        builder.Append("&nsub;");
                        continue;
                    }
                    case 0x2286:
                    {
                        builder.Append("&sube;");
                        continue;
                    }
                    case 0x2287:
                    {
                        builder.Append("&supe;");
                        continue;
                    }
                    case 0x2295:
                    {
                        builder.Append("&oplus;");
                        continue;
                    }
                    case 0x2297:
                    {
                        builder.Append("&otimes;");
                        continue;
                    }
                    case 0x2308:
                    {
                        builder.Append("&lceil;");
                        continue;
                    }
                    case 0x2309:
                    {
                        builder.Append("&rceil;");
                        continue;
                    }
                    case 0x230a:
                    {
                        builder.Append("&lfloor;");
                        continue;
                    }
                    case 0x230b:
                    {
                        builder.Append("&rfloor;");
                        continue;
                    }
                    case 0x22c5:
                    {
                        builder.Append("&sdot;");
                        continue;
                    }
                    case 0x22a5:
                    {
                        builder.Append("&perp;");
                        continue;
                    }
                    case 0x2329:
                    {
                        builder.Append("&lang;");
                        continue;
                    }
                    case 0x232a:
                    {
                        builder.Append("&rang;");
                        continue;
                    }
                    case 0x25ca:
                    {
                        builder.Append("&loz;");
                        continue;
                    }
                    case 0x2660:
                    {
                        builder.Append("&spades;");
                        continue;
                    }
                    case 0x2663:
                    {
                        builder.Append("&clubs;");
                        continue;
                    }
                    case 0x2665:
                    {
                        builder.Append("&hearts;");
                        continue;
                    }
                    case 0x2666:
                    {
                        builder.Append("&diams;");
                        continue;
                    }
                }
                if (i <= 0x7f)
                {
                    builder.Append((char) i);
                }
                else
                {
                    builder.Append("&#" + i + ";");
                }
            }
            return builder.ToString();
        }
    }
}

